<template>
  <div>
    <!-- <h1>我的</h1> -->
    <div class="mine">
      <div class="title">
        <div class="font">
          <h1 v-show="title">我的</h1>
        </div>
        <div class="icon">
          <i class="iconfont icon-moon_line"></i>
          <i
            class="light iconfont icon-icon-test"
            @click="$router.push('/login')"
          ></i>
        </div>
      </div>

      <div class="myself" @scroll="onScrolled">
        <div class="headMine">
          <div class="img">
            <img
              :src="
                headImg ||
                '//bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/218b7007c9437da79e34c85b219cf2ab.jpg'
              "
            />
          </div>

          <h1 @click="$router.push('/login')" v-show="!username">登录/注册</h1>
          <h1>{{ username }}</h1>
        </div>

        <div class="todayRe">
          <div class="box">
            <h1>今日充值赠返</h1>
            <ul>
              <li @click="$router.push('/mineBean')">
                <h1>0</h1>
                <p>书豆</p>
              </li>
              <li @click="$router.push('/BeanTicket')">
                <h1>0</h1>
                <p>豆券</p>
              </li>
              <li @click="$router.push('/chapter')">
                <h1>0</h1>
                <p>章节券</p>
              </li>
              <li @click="$router.push('/recomTicket')">
                <h1>1</h1>
                <p>推荐票</p>
              </li>
            </ul>
          </div>
        </div>

        <div class="info">
          <ul>
            <li @click="$router.push('/message')">
              <i class="iconfont icon-xiaoxi"></i>
              <p>消息</p>
            </li>
            <li @click="$router.push('/collection')">
              <i class="iconfont icon-iconStar"></i>
              <p>收藏</p>
            </li>
            <li @click="$router.push('/review')">
              <i class="iconfont icon-pinglun"></i>
              <p>书评</p>
            </li>
            <li @click="$router.push('/history')">
              <i class="iconfont icon-lishijilu"></i>
              <p>阅历</p>
            </li>
          </ul>
        </div>

        <div class="wirter">
          <div class="content">
            <p>作者中心</p>
            <h1>零门槛创作，千万现金扶持</h1>
            <i class="iconfont icon-gengduo"></i>
          </div>
        </div>

        <div class="mess">
          <ul>
            <li>
              <p>奖品中心</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
            <li>
              <p>我的书籍</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
            <li>
              <p>绑兑换码</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
            <li>
              <p>阅读爱好</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
            <li>
              <p>意见反馈</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
            <li>
              <p>用户调研</p>
              <i class="iconfont icon-gengduo"></i>
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getUsersInfo } from "../api/userInfo";
export default {
  props: ["uid"],
  data() {
    return {
      active: "mine",
      title: false,
      headImg: null, // 头像
      username: null, // 用户名
    };
  },
  methods: {
    onScrolled() {
      this.scrolled = window.scrollY > 0;
      if (this.scrolled) {
        this.title = true;
      } else {
        this.title = false;
      }
    },
    getUsersInfoFun() {
      if (this.uid || localStorage.uid) {
        getUsersInfo({ id: this.uid }).then((data) => {
          console.log(this.uid);
          console.log(data);
          this.headImg = data.img;
          this.username = data.username;
        });
      }
    },
  },
  created() {
    this.getUsersInfoFun();
  },
  mounted() {
    window.addEventListener("scroll", this.onScrolled);
  },
};
</script>

<style lang="less">
.mine {
  margin-bottom: 50px;
  .title {
    width: 100%;
    background-color: #f6f7f9;
    position: fixed;
    top: 0;
    display: flex;
    height: 45px;
    text-align: center;
    line-height: 45px;
    .font {
      flex: 1;
      padding-left: 80px;
      font-size: 18px;
    }
    .icon {
      flex: 0 0 80px;
      .iconfont {
        font-size: 20px;
      }
      .light {
        margin-left: 20px;
      }
    }
  }
  .myself {
    padding-top: 50px;
    .headMine {
      padding: 15px;
      display: flex;
      align-items: center;
      .img {
        margin-right: 15px;
        img {
          width: 60px;
          height: 60px;
          border-radius: 50%;
          border: 3px solid #fff;
        }
      }
      h1 {
        font-size: 20px;
      }
    }
    .todayRe {
      padding: 10px 15px;
      .box {
        border-radius: 8px;
        background-color: #fff;
        padding: 8px 14px;
        h1 {
          padding: 15px 0 8px 0;
        }
        ul {
          display: flex;
          justify-content: space-between;
          text-align: center;
          padding: 0 15px;
          padding-top: 6px;
          li {
            h1 {
              font-size: 18px;
            }
            p {
              font-size: 12px;
              color: #999;
            }
          }
        }
      }
    }
    .info {
      padding: 8px 15px;
      ul {
        display: flex;
        justify-content: space-between;
        background-color: #fff;
        border-radius: 8px;
        text-align: center;
        padding: 16px 30px;
        li {
          i {
            font-size: 28px;
          }
          p {
            margin-top: 8px;
            font-size: 13px;
            color: #999;
          }
        }
      }
    }
    .wirter {
      padding: 8px 15px;
      .content {
        background-color: #fff;
        border-radius: 8px;
        display: flex;
        justify-content: space-between;
        padding: 20px 15px;
        p {
          font-size: 14px;
        }
      }
    }
    .mess {
      padding: 8px 15px;
      ul {
        background-color: #fff;
        padding: 0 15px;
        border-radius: 8px;
        li {
          display: flex;
          justify-content: space-between;
          padding: 20px 0;
          p {
            font-size: 14px;
          }
        }
      }
    }
  }
}
</style>